home *** CD-ROM | disk | FTP | other *** search
/ Directorty Opus 5 - Magellan 2 / Opus 5 - Magellan 2.iso / Extras / MailBox1.5 / MailBox.dopus5 < prev    next >
Text File  |  1996-10-25  |  10KB  |  342 lines

  1. /* MailBox ARexx Module for Directory Opus 5.5
  2.    ©1996 Mark Rigby-Jones for mrjsw
  3.    mark.rigby-jones@keble.oxford.ac.uk <*> http://users.ox.ac.uk/~kebl0206/
  4.  
  5. $VER: MailBox.dopus5 1.5 (25.10.96)
  6.  
  7.    For information on usage, see the supplied MailBox.guide file.           */
  8.  
  9. /*---------------------------------Settings---------------------------------*/
  10. MailFile  = "Home:Mail/mrj"              /* The mailbox file to monitor     */
  11. EmptyIcon = "DOpus5:Icons/mail_empty"    /* icon to display for no mail     */
  12. OldIcon   = "DOpus5:Icons/mail_old"      /* icon to display for old mail    */
  13. NewIcon   = "DOpus5:Icons/mail_new"      /* icon to display for new mail    */
  14. MailPort  = "T:MailRdy"                  /* Port to listen on for new mail  */
  15. SnapFile  = "DOpus5:System/MailBox.snap" /* File to store snapshot position */
  16. StartUp   = "yes"                        /* Open icon on startup yes/no     */
  17. ILock     = 0                            /* Initial lock state 0=yes/1=no   */
  18. /*-------------------------------End Settings-------------------------------*/
  19.  
  20. Options Results
  21. Options FailAt 11
  22. Signal On Syntax
  23.  
  24. Parse Arg DOpusPort Function Source Dest Cmd
  25. Cmd=Upper(Cmd)
  26.  
  27. Address Value DOpusPort
  28.  
  29. If ~Show("L","rexxsupport.library") Then
  30.     Call AddLib("rexxsupport.library",0,-30,0)
  31.  
  32. /* Module initialised by DOpus */
  33.  
  34. If Function = "init" Then Do
  35.     DOpus Command "MailBox" Program "MailBox" Desc "'Open/Close/Refresh MailBox'" Template "CLOSE/S"
  36.     If StartUp = "no" Then Exit
  37.     End
  38.  
  39. /* If MailBox is already running, send appropriate
  40.    commands to it rather than opening an icon ourselves. */
  41.  
  42. Call Forbid()
  43.  
  44. If Show(P,MailPort) Then Do
  45.     Call Permit()
  46.     Address Value MailPort
  47.     If Cmd = "CLOSE" Then
  48.         Close
  49.     Else
  50.         Refresh
  51.     Exit
  52.     End
  53.  
  54. If Cmd="CLOSE" Then Exit
  55.  
  56. /* Try to open our message port. */
  57.  
  58. If ~OpenPort(MailPort) Then Do
  59.     Call Permit()
  60.     DOpus Request '"MailBox: Unable to open message port 'MailPort'" OK'
  61.     Exit
  62.     End
  63.  
  64. Call Permit()
  65.  
  66. /* Read a previously snapshotted position. */
  67.  
  68. If Open(FileHandle,SnapFile) Then Do
  69.     Position = "Pos "ReadLn(FileHandle)
  70.     ILock    = ReadCh(FileHandle)
  71.     Call Close(FileHandle)
  72.     End
  73. Else Do
  74.     Position = ""
  75.     End
  76.  
  77. IconName   = ""
  78. Mails      = 0
  79. Size       = -1
  80. Flag       = 3
  81. stem.COUNT = 5
  82. stem.0     = "Lock"
  83. stem.1     = "Un-Lock"
  84. stem.2     = "---"
  85. stem.3     = "Refresh"
  86. stem.4     = "Mailer..."
  87.  
  88. /* Main Loop */
  89.  
  90. Do Until Flag<0
  91.  
  92.     /* Do we want to refresh the icon? */
  93.  
  94.     If Flag>0 Then Do
  95.         RefreshTime = Time()
  96.  
  97.         /* Get the size of the mailbox. */
  98.  
  99.         If Exists(MailFile) Then Do
  100.             NewSize     = Word(StateF(MailFile),2)
  101.             NewIconName = OldIcon
  102.             End
  103.         Else Do
  104.             NewSize     = 0
  105.             NewIconName = EmptyIcon
  106.             End
  107.  
  108.         /* New mail message recieved (but we check to see
  109.            that the mailbox has increased in size too.    */
  110.  
  111.         If (Flag=2 & NewSize>Size) Then Do
  112.             DOpus SetAppIcon IconHandle Busy On
  113.  
  114. /*---------------------------------New Mail---------------------------------*/
  115.  
  116.             /* Example: Play a sample
  117.  
  118.             'Command Play Quiet Work:Music/Samples/newmail'
  119.  
  120.             */
  121.  
  122. /*-------------------------------End New Mail-------------------------------*/
  123.             Address Value DOpusPort
  124.             DOpus SetAppIcon IconHandle Busy Off
  125.             Mails       = Mails+1
  126.             LastTime    = RefreshTime
  127.             Plural      = "s"
  128.             If Mails = 1 Then Do
  129.                 OldSize = Size
  130.                 Plural  = ""
  131.                 End
  132.             End
  133.  
  134.         If Mails>0 Then
  135.             NewIconName = NewIcon
  136.  
  137.         Size=NewSize
  138.         KSize = (512+Size)%1024
  139.  
  140.         /* Create text for icon and information requester. */
  141.  
  142.         Select
  143.             When Size=0 Then Do
  144.                 Label = "No mail"
  145.                 About = 'no email whatsoever'
  146.                 End
  147.             When Mails>0 Then Do                
  148.                 NSize = (512+Size-OldSize)%1024
  149.                 Label = Mails" New, "NSize"K"
  150.                 About = KSize'K of email, of which 'Nsize'K,'||'0A'x||Mails' message'Plural', is new. The last'||'0A'x||'mail arrived at 'LastTime
  151.                 End
  152.             Otherwise
  153.                Label = KSize"K old mail"
  154.                About = KSize'K of email, none new'
  155.             End
  156.  
  157.         /* Update the icon and/or text. */
  158.  
  159.         If NewIconName ~= IconName Then Do
  160.             If Flag ~= 3 Then
  161.                 DOpus RemAppIcon IconHandle
  162.             IconName   = NewIconName
  163.             DOpus AddAppIcon MailPort '"'Label'"' 1 Position Icon '"'IconName'"' Info Snap Close Local Menu stem.
  164.             IconHandle = RESULT
  165.             End
  166.         Else
  167.             DOpus SetAppIcon IconHandle Text '"'Label'"'
  168.  
  169.         If ILock Then
  170.             DOpus SetAppIcon IconHandle Locked On
  171.         End
  172.  
  173.     /* Wait for a message to the message port. */
  174.  
  175.     Flag = 0
  176.     Call WaitPkt(MailPort)
  177.     Packet = GetPkt(MailPort)
  178.  
  179.     If Packet=Null() Then
  180.  
  181.         /* Not an ARexx message, assume it's about new mail. */
  182.  
  183.         Flag=2
  184.  
  185.     Else Do
  186.  
  187.         /* Parse input to find out what the command is. */
  188.  
  189.         Cmd=UPPER(GetArg(Packet,0))
  190.         If (Cmd="SNAPSHOT" | Cmd="DROPFROM" | Cmd="MENU") Then
  191.             Data = GetArg(Packet,2)
  192.         Call Reply(Packet,0)
  193.  
  194.         If Cmd = "MENU" Then Do
  195.             Select
  196.                 When Data = 0 Then
  197.                     Cmd = "LOCK"
  198.                 When Data = 1 Then
  199.                     Cmd = "UNLOCK"
  200.                 When Data = 3 Then
  201.                     Cmd = "REFRESH"
  202.                 When Data = 4 Then
  203.                     Cmd = "DOUBLECLICK"
  204.                 End
  205.             End
  206.  
  207.         If Cmd = "MENUHELP" Then
  208.             Cmd = "INFO"
  209.  
  210.         /* Now process that command. */
  211.  
  212.         Select
  213.             When Cmd = "REFRESH" Then
  214.                 Flag = 1
  215.  
  216.             When Cmd = "CLOSE" Then
  217.                 Flag = -1
  218.  
  219.             When Cmd = "REMOVED" Then
  220.                 Flag = -2
  221.  
  222.             When Cmd = "INFO" Then Do
  223.  
  224.                 /* Information requester - some of
  225.                    the text was generated earlier. */
  226.  
  227.                 DOpus SetAppIcon IconHandle Busy On
  228.                 DOpus Request '"MailBox for Directory Opus 5.5'||'A'x||'©1996 Mark Rigby-Jones'||'0A0A'x||'As of 'RefreshTime', you have'||'0A'x||About'." OK|Close'
  229.                 If RC = 0 Then
  230.                     Flag = -1
  231.                 Dopus SetAppIcon IconHandle Busy Off
  232.                 End
  233.  
  234.             When Cmd = "SNAPSHOT" Then Do
  235.  
  236.                 /* Icon snapshot - save it to the specified file. */
  237.  
  238.                 Position = "Pos "Data
  239.                 If Open(FileHandle,SnapFile,W) Then Do
  240.                     Call WriteLn(FileHandle,Data)
  241.                     Call WriteCh(FileHAndle,ILock)
  242.                     Call Close(FileHandle)
  243.                     End
  244.                 End
  245.  
  246.             When Cmd = "UNSNAPSHOT" Then Do
  247.  
  248.                 /* Unsnapshot icon - delete the file. */
  249.  
  250.                 Position = ""
  251.                 Call Delete(SnapFile)
  252.                 End
  253.  
  254.             When Cmd = "LOCK" Then Do
  255.                 ILock = 1
  256.                 DOpus SetAppIcon IconHandle Locked On
  257.                 End
  258.  
  259.             When Cmd = "UNLOCK" Then Do
  260.                 ILock = 0
  261.                 DOpus SetAppIcon IconHandle Locked Off
  262.                 End
  263.  
  264.             When Cmd = "DOUBLECLICK" Then Do
  265.  
  266.                 /* Icon double-clicked - put the icon in busy-mode whilst
  267.                    we execute user code, and reset the new mail count.    */
  268.  
  269.                 DOpus SetAppIcon IconHandle Busy On
  270.  
  271. /*-------------------------------Go To Mailer-------------------------------*/
  272.  
  273.                 /* Example: Load/Bring to front Mailer
  274.                    This routine works with MetaTool 40.5, assuming you
  275.                    have some ScreenToFront Program.
  276.  
  277.                 If ~Show(P,"METATOOL") Then
  278.                     Address COMMAND "Run Home:MetaTool/MetaTool"
  279.                 Else Do
  280.                     Address METATOOL "SHOW"
  281.                     Address COMMAND "ScreenToFront MetaTool"
  282.                     End
  283.  
  284.                 */
  285.  
  286. /*-----------------------------End Go To Mailer-----------------------------*/
  287.  
  288.                 Address Value DOpusPort
  289.                 DOpus SetAppIcon IconHandle Busy Off
  290.                 Mails = 0
  291.                 Flag  = 1
  292.                 End
  293.  
  294.             When Cmd = "DROPFROM" Then Do
  295.  
  296.                 /* Icon double-clicked - put the icon in
  297.                    busy-mode whilst we execute user code. */
  298.  
  299.                 DOpus SetAppIcon IconHandle Busy On
  300.  
  301. /*------------------------Files Dropped on AppIcon--------------------------*/
  302.  
  303.                 /* Example: Load mailbox into your mailer?
  304.                             Add file as attatchment?
  305.                 */
  306.  
  307. /*----------------------End Files Dropped on AppIcon------------------------*/
  308.  
  309.                 Address Value DOpusPort
  310.                 DOpus SetAppIcon IconHandle Busy Off
  311.                 Flag = 1
  312.                 End
  313.  
  314.             Otherwise
  315.  
  316.                 /* Not a recognised command - assume it's about new mail. */
  317.  
  318.                 Flag = 2
  319.             End
  320.         End
  321.     End
  322.  
  323. /* Exit cleanly for whatever reason. */
  324.  
  325. If Flag = -1 Then
  326.     DOpus RemAppIcon IconHandle
  327.  
  328. Call ClosePort(MailPort)
  329.  
  330. Exit
  331.  
  332. /* Syntax error ocurred - exit cleanly with a helpful message. */
  333.  
  334. Syntax:
  335.  
  336. Call ClosePort(MailPort)
  337. DOpus RemAppIcon IconHandle
  338. DOpus Request '"MailBox: Error, line 'SIGL' : 'ErrorText(RC)'" OK'
  339.  
  340. Exit
  341.  
  342.